<?php
/**
 * ProjectName: Grapes.
 * Created by LemonZ.
 * FileName: CarouselSeat.php
 * Date: 2019/2/14
 * Time: 15:35
 * Description:
 */

namespace app\admin\controller;


use app\common\controller\Admin;
use app\common\model\CarouselSeat as CarouselSeatModel;
use think\facade\Request;

class CarouselSeat extends Admin
{
    /**
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $position = new CarouselSeatModel();
        if(Request::isAjax())
        {
            return $position->tableData(input('param.'));
        }
        return $this->fetch();
    }

    /**
     * 添加广告位
     * @return array|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function add()
    {
        $this->view->engine->layout(false);
        $position = new CarouselSeatModel();
        if(Request::isPost())
        {
            return $position->addData(input('param.'));
        }
        return $this->fetch('add',['list'=>config('carousel_seat.list')]);
    }

    /**
     * 广告位编辑
     * @return array|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function edit()
    {
        $this->view->engine->layout(false);
        $positionModel = new CarouselSeatModel();
        if(Request::isPost())
        {
            return $positionModel->saveData(input('param.'));
        }
        $info = $positionModel->where('id',input('param.id/d'))->find();
        if (!$info) {
            return error_code(10002);
        }

        return $this->fetch('',['info'=>$info]);
    }

    /**
     * 广告位删除
     * @return array
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function del()
    {
        $position = new CarouselSeatModel();
        return $position->del(input('param.id/d'));
    }
}